package spe.model.spem;

import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;

import spe.model.notation.Link;

public class SPERootElement extends SPEMElementImpl implements SPEMElement
{
	protected IProject project = null;
	private IFile _file;
	private List<SPEMElement> elements = new ArrayList<SPEMElement>();
	private List<Link> links = new ArrayList<Link>();
	
	public void addLink(Link l)
	{
		links.add(l);
		firePropertyChange("Link", null, l);
	}
	
	public void removeLink(Link l)
	{
		links.remove(l);
		firePropertyChange("Link", l, null);
	}
	
	public void addChildElement(SPEMElement ml)
	{
		elements.add(ml);
		firePropertyChange("Element", null, ml);
	}
	
	public void removeChildElement(SPEMElement ml)
	{
		elements.remove(ml);
		firePropertyChange("Element", ml, null);
	}
	
	public SPEMElement[] getElements()
	{
		return elements.toArray(new SPEMElement[elements.size()]);
	}
	
	public SPEMElement[] getElement(Class aClass)
	{
		SPEMElement[] arr = elements.toArray(new SPEMElement[elements.size()]);
		List<SPEMElement> lst = new ArrayList<SPEMElement>();
		for(int i=0; i<arr.length; i++)
			if(aClass.isInstance(arr[i]))
				lst.add(arr[i]);
		return lst.toArray(new SPEMElement[lst.size()]);
	}
	
	public IProject getProject() 
	{
		return project;
	}

	public void setProject(IProject proj)
	{
		this.project = proj;
	}
	
	public IFile getFile() 
	{
		return _file;
	}

	public void setFile(IFile f)
	{
		this._file = f;
	}
	
	@Override
	public void propertyChange(PropertyChangeEvent arg0)
	{
		// TODO Auto-generated method stub

	}
}
